﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;

namespace System
{
    // NOTE : this is a TEMPORARY and a very minimalistic implementation of Tuple'2, 
    // as defined in http://devdiv/sites/docs/NetFX4/CLR/Specs/Base Class Libraries/Tuple Spec.docx
    // We will remove this after we move to v4 and Tuple is actually in there
    public struct Tuple<TFirst, TSecond>
    {
        public Tuple(TFirst first, TSecond second)
        {
            this = new Tuple<TFirst, TSecond>();
            this.First = first;
            this.Second = second;
        }

        public TFirst First { get; private set; }
        public TSecond Second { get; private set; }

        public override bool Equals(object obj)
        {
            if (obj is Tuple<TFirst, TSecond>)
            {
                Tuple<TFirst, TSecond> that = (Tuple<TFirst, TSecond>)obj;
                return object.Equals(this.First, that.First) && object.Equals(this.Second, that.Second);
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return ((this.First != null) ? this.First.GetHashCode() : 0) ^ ((this.Second != null) ? this.Second.GetHashCode() : 0);
        }

        public static bool operator ==(Tuple<TFirst, TSecond> left, Tuple<TFirst, TSecond> right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(Tuple<TFirst, TSecond> left, Tuple<TFirst, TSecond> right)
        {
            return !left.Equals(right);
        }
    }
}
